<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改系统用户</title>
<base href="<%=basePath%>" />
<%@ include file="../../cuv_include.jsp"%>
<%@ include file="../../list_include.jsp"%>
<link rel="stylesheet" href="<%=basePath%>/js/uploadify/css/uploadify.css" type="text/css"></link>
<script language="JavaScript" type="text/javascript" src="<%=basePath%>js/my97/WdatePicker.js" defer="defer"></script>
<script type="text/javascript" src="<%=basePath%>/js/uploadify/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<style type="text/css">
fieldset,legend,form,table,tr,td,textarea {
	margin: 0;
	padding: 0
}

label {
	font-weight: bold;
}

table {
	margin: 10px 10px
}

;
td {
	line-height: 40px;
}

input[type="text"] {
	width: 250px;
}

input[type="password"] {
	width: 250px;
}

input[type="textarea"] {
	width: 250px;
}
</style>

<script type="text/javascript">
		var projectId = null;
	  $(document).ready(function(){
		  $("#attview").tablesorter({theme:'green', widgets:['zebra', "resizable"]});
		  
		  $("#allRoles").dblclick(function(){
	    	  var value = $("#allRoles").val();
	          moveRight(value);
	      });

	      $("#selectedRoles").dblclick(function(){
	    	  var value = $("#selectedRoles").val();
	    	  moveLeft(value);
	      });

	      $("#btn_right").click(function(){
	    	  var value = $("#allRoles").val();
	          moveRight(value);
	      });

	      $("#btn_left").click(function(){
	    	  var value = $("#selectedRoles").val();
	    	  moveLeft(value);
	      });
	      
	      $("#btn_allright").click(function(){
	    	  moveRightAll();
	      });

	      $("#btn_allleft").click(function(){
	    	  moveLeftAll();
	      });
		  
	        var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
	        var options2 = {dataType: 'json', success: process2};
	        $("#btn_update").click(function(){
	        	$("#btn_update").attr("disabled","disabled");
	            $("#userForm").ajaxSubmit(options);
	            return false;
	        });
	        $("#commentForm").submit(function(){
	        	$("#btn_insert").attr("disabled","disabled");
	            $(this).ajaxSubmit(options2);
	            return false;
	        });
	        
	        $("#file_upload").uploadify({   
	            'height'        : 27,    
	            'width'         : 80,     
	            'buttonText'    : '添加附件',   
	            'removeCompleted': false,         //上传完毕上传列表是否去除 
	            'fileSizeLimit': '50MB',          //上传文件大小设置 单位可以是B、KB、MB、GB 
	            'swf'           : '<%=basePath%>js/uploadify/uploadify.swf',   
	            'uploader'      : '<%=basePath%>pjcost/project/upload.do',   
	            'auto'          : false,   
	            'formData'      : {'projectId':''},  
	            'fileTypeExts'  : '*.*',   
	            'onUploadStart' : function(file) {   
	                  $("#file_upload").uploadify("settings","formData", {'projectId':projectId});   
	             },   
	            'onUploadSuccess':function(file, data, response){ 
	          	  $('#' + file.id).find('.data').html(' 上传完毕');
	             },   
	            'onUploadComplete':function(file){   
	                  window.close();   
	             }   
	        });
	  });
	  
	  function startUpload(){   
		  projectId = $("#projectId").val();
		  if(projectId.replace(/\s/g,'') == '')
		  {
			  alert("projectId不能为空！");   
	          return false;    
		  }else
	      {
			  $('#file_upload').uploadify('upload','*');   
	      }
	   } 
	  
	  function beforeSubmit() {
		  if(isEmpty($("#expectedTime").val())) { $('#error_label').text("错误信息：预计时间不能为空！"); 
		  $("#p_error").show();
		  $("#btn_update").removeAttr("disabled");  
		  return false; }
		  
		  var str = $("#connector").val(); 
	      var reg=new RegExp(/[0-9]/);
	      if(reg.test(str)){
	      }else{
	       $('#error_label').text("错误信息：请填写客户经理电话！"); 
	       $("#p_error").show();
	       $("#btn_update").removeAttr("disabled");
	       return false;
	      }
// 			if(isEmpty($("#cnname").val())) { alert("别名不能为空！"); return false; }
// 			if(!validateSize($("#cnname").val(), 2, 32)) { alert("别名不符合规格！"); return false; }   
			
// 			if(!isEmpty($("#mobile").val()) && !isMobile($("#mobile").val())) { alert("手机号不符合规格！"); return false; }  
// 			if(!isEmpty($("#email").val()) && !isEmail($("#email").val())) { alert("Email不符合规格！"); return false; }
			
			return true;
	  }
	  
	  function process(responseJson) {
		  $("#btn_update").removeAttr("disabled");
	        if(responseJson.code == 0) {
	            $('#error_label').text("错误信息：" + responseJson.message);
	            $("#p_error").show();
	            return;
	        }
	        var qs = $("#qs").val();
	        location.href = "<%=basePath%>pjcost/project/userList.do?" + qs;
	}
	  function process2(responseJson) {
		  $("#btn_insert").removeAttr("disabled");
		  if(responseJson.code == 0) return;
	        var str = "<div style='word-wrap:break-word; word-break:normal; margin: 10px 0 0 0; line-height: 1.6;'>"+
     		responseJson.createtime+"&nbsp;&nbsp;<font color='red'>"+responseJson.username+"</font>："+
     		"<span style='color:#00A;'>"+responseJson.content+"</span></div>";
	  		$("#commentSet").prepend(str);
	  		$("#content").val("");
	    }
	  function back(){
		  var qs = $("#qs").val();
	        location.href = "<%=basePath%>pjcost/project/userList.do?" + qs;
	  }
	  
	  function updpchange(){
		  var value = $("#btn_upload").val();
		  if(value == "新增附件") $("#btn_upload").val("收起");
		  else $("#btn_upload").val("新增附件");
		   $("#uploadDiv").toggle();
	  }
	  
	  function moveRight(value){
	      if(value == null) return;
	      
	      var text = $("#allRoles option[value="+ value +"]").text();
	      var str = $("#allRoles option[value="+ value +"]").attr("deptNo");
	      
	      var html = "<option value='"+value+"' deptNo='"+str+"'>"+text+"</option>";
	      $("#selectedRoles").append(html);
	      
	      $("#allRoles option[value="+ value +"]").remove();
	      
	  };

	  function moveLeft(value){
	      var pvalue = $("#depts").val();
	      if(value == null) return;
	      var text = $("#selectedRoles option[value="+ value +"]").text();
	      
	      var str = $("#selectedRoles option[value="+ value +"]").attr("deptNo");
		  if(str == pvalue){
	          var html = "<option value='"+value+"' deptNo='"+str+"'>"+text+"</option>";
	          $("#allRoles").append(html);
		  }
	      $("#selectedRoles option[value="+ value +"]").remove();
	      
	  };
	  function hid(){
			$("#select1").hide();
			$("#select2").hide();
			$("#select3").hide();
			$("#select4").hide();
			$("#select5").hide();
			$("#select6").hide();
		  	  };
		  	function showselect(){
				$("#select1").show();
				$("#select2").show();
				$("#select3").show();
				$("#select4").show();
				$("#select5").show();
				$("#select6").show();
			  	  };
		function conf(){
	 		var length = $("#selectedRoles option").length;
	        var value = "";
	        var valuecn = "";
	        $("#selectedRoles option").each(function(i){
	            value = value + $(this).val();
	            valuecn = valuecn + $(this).text();
	            if(i != length - 1) {
	            	value += ",";
	            	valuecn += ",";
	            }
	        });
	        $("#operator").val(value);
	        $("#operator2").val(valuecn);
	        hid();
	 	 	  };
	  function change(){
		  var pvalue = $("#depts").val();
		  $("#allRoles").empty();
		  $("#allRoles").innerHTML = ""; // 清空下拉菜单
		  if(pvalue == null || pvalue == "") {
// 			  <c:forEach items="${users}" var="myList" varStatus="status">
// 			  	  var flag1 = true ;
// 			  	  var id1	= "<c:out value="${myList.deptNo}"></c:out>";
// 	    		  $("#selectedRoles option").each(function(i){
// 		                var value = $(this).val();
// 		                if(id1 == value){
// 		                	flag1 = false;}
// 		            });
// 	    	  		if(flag1){
// 	    	  			var html = "<option value='"+"<c:out value="${myList.enname}"></c:out>"+"' deptNo='"+"<c:out value="${myList.deptNo}"></c:out>"+"'>"+"<c:out value="${myList.cnname}"></c:out>"+"</option>";
// 	    	  			$("#allRoles").append(html);
// 	    	  		}
// 			  </c:forEach>
			  return;
		  }
		  <c:forEach items="${users}" var="myList" varStatus="status">
		  		var partitionsId	= "<c:out value="${myList.deptNo}"></c:out>";
		  		var id	= "<c:out value="${myList.enname}"></c:out>";
		  		var flag = true ;
		  		if(partitionsId != pvalue ){
		  			flag = false;}
	  	  	$("#selectedRoles option").each(function(i){
	            var value = $(this).val();
	            if(id == value){
	            	flag = false;}
	        });
		  		if(flag){
		  			var html = "<option value='"+"<c:out value="${myList.enname}"></c:out>"+"' deptNo='"+"<c:out value="${myList.deptNo}"></c:out>"+"'>"+"<c:out value="${myList.cnname}"></c:out>"+"</option>";
		  			$("#allRoles").append(html);
		  		}
		  		
				</c:forEach>
	  };
	  
	  function moveRightAll(){
	 	 var allRoles = $("#allRoles option");
	 	 for(var i=0;i<allRoles.length;i++){
	 		 var value = allRoles[i].value;
	 		 if(value == null) continue;
	 		 moveRight(value);
	 	 }
	   }
	   function moveLeftAll(){
	 	  var selectedRoles = $("#selectedRoles option");
	 	  for(var i=0;i<selectedRoles.length;i++){
	     		 var value = selectedRoles[i].value;
	      		 if(value == null) continue;
	      		 moveLeft(value);
	 	  }
	   }
</script>
</head>

<body>
	<div style="width: 1408px;">
	<div style="float:left; width: 55%;">
		<div style="width: 100%">
			<form id="userForm" method="post" action="pjcost/project/update.do">
				<input type="hidden" name="id" id="id" value="${project.id}" /> 
				<input type="hidden" name="projectId" id="projectId" value="${project.id}" /> 
				<input type="hidden" name="lastModifyTime" value="${project.lastModifyTime}" /> 
				<input type="hidden" name="province" id="province" value="${project.province }" /> 
				<input type="hidden" name="name" id="name" value="${project.name }" /> 
				<input type="hidden" name="code" value="${project.code}" /> 
				<input type="hidden" name="applyUser" id="applyUser" value="${project.applyUser }" />
				<input type="hidden" name="applyTime" value="${project.applyTime}" /> 
				<input type="hidden" name="operator" id="operator" value="${project.operator}" />
				<input type="hidden" name="status" id="status" value="${project.status}" />
				<input id="qs" name="qs" type="hidden" value="${qs}" />
				<p id="p_error" style="margin: 10px 10px;">
					<label id="error_label" style="color: red;"></label>
				</p>
				<table>
					<tr>
						<td><label for="name">项目名：</label></td>
						<td colspan="2"><input type="text" name="name" disabled="disabled"
							id="name" value="${project.name }" /></td>
					</tr>
					<tr>
						<td><label for="province">省份：</label></td>
						<td colspan="2"><input type="text" name="province" disabled="disabled" id="province" value="${provinces[project.province]}" /></td>
					</tr>
					<tr>
						<td><label for="applyUser">申请人：</label></td>
						<td colspan="2"><input type="text" name="applyUser" id="applyUser"
							disabled="disabled" value="${user.cnname }" /> <font color="red">&nbsp;*&nbsp;&nbsp;</font>
						</td>
					</tr>
					<tr>
            <td><label for="operator">经办人：</label></td>
            <td colspan="2">
            	<input type="text" name="operator2" id="operator2" disabled="disabled" value="${operator}" />
            	<input type="button" id="btn_show" value="请选择" onclick="showselect();" style="width:80px;" />
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            </td>
            </tr>
			     <tr id = "select1" style="display:none;"><td><label>所属部门：</label></td></tr>
                 <tr id = "select2" style="display:none;">
                   <td>
	                 <select name="depts" id="depts" style="width: 150px;" onchange="change();">
	                 	<option value=""></option>
	                 	<c:forEach items="${depts}" var="myList" varStatus="status">
	                 		<option value="${myList.deptNo}">${myList.deptName}</option>
	                 	</c:forEach>
	                 </select>
	               </td>  
                 </tr>
                  <tr id = "select3" style="display:none;">
                      <td><label>该部门下未选择人员：</label></td>
                      <td></td>
                      <td><label>已选择人员：</label></td>
                  </tr>
                  <tr id = "select4" style="display:none;">
                      <td>
                          <select id="allRoles" name="allRoles" multiple="multiple" style="width: 165px; height: 200px;" >
                          </select>
                      </td>
                      <td style="text-align: center;">
                          <input id="btn_allright" type="button" value="&gt;&gt;" style="width: 36px;"/><br/><br/>
                          <input id="btn_right" type="button" value="&gt;" style="width: 36px;"/><br/><br/>
                          <input id="btn_left" type="button" value="&lt;" style="width: 36px;"/><br/><br/>
                          <input id="btn_allleft" type="button" value="&lt;&lt;" style="width: 36px;"/>
                      </td>
                      <td>
                          <select id="selectedRoles" name="selectedRoles" multiple="multiple" style="width: 165px; height: 200px;">
                          	<c:forEach items="${selectUser}" var="myList" varStatus="status">
	                             <option value="${myList.enname}" deptNo="${myList.deptNo}">${myList.cnname}</option>
                             </c:forEach>
                          </select>
                      </td>
                  </tr>
              <tr style="clear: both;" id = "select5" style="display:none;"></tr>
              <tr id = "select6"  style="display:none;">
                  <td><input type="button" id="btn_submit" value="确认" onclick="conf();" style="width:80px;" /><input
                   type="button" id="btn_back" value="返回" onclick="hid();" style="width:80px;" /></td>
              </tr>
					<tr>
						<td><label for="expectedTime">预计实现时间：</label></td>
						<td colspan="2"><input type="text" name="expectedTime" id="expectedTime"
							onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
							class="Wdate" value="${project.expectedTime }" /> <font
							color="red">&nbsp;*&nbsp;&nbsp;</font></td>
					</tr>
					<tr>
						<td><label for="projectedScale">预计规模：</label></td>
						<td colspan="2"><input type="text" name="expectedScale"
							id="expectedScale" value="${project.expectedScale }" /></td>
					</tr>
					<tr>
						<td><label for="connector">客户经理：</label></td>
						<td colspan="2"><input type="text" name="connector" id="connector"
							value="${project.connector }" /> <font color="red">&nbsp;*&nbsp;&nbsp;</font>
							</td>
					</tr>
					<tr>
						<td><label for="customerContactor">用户联系人：</label></td>
						<td colspan="2"><input type="text" name="customerContactor"
							id="customerContactor" value="${project.customerContactor }" />
						</td>
					</tr>
					<tr>
						<td><label for="customerPhone">用户联系人电话：</label></td>
						<td colspan="2"><input type="text" name="customerPhone"
							id="customerPhone" value="${project.customerPhone }" /></td>
					</tr>
					<tr>
						<td><label for="customerCompany">用户单位名称：</label></td>
						<td colspan="2"><input type="text" name="customerCompany"
							id="customerCompany" value="${project.customerCompany }" /></td>
					</tr>
					<tr>
						<td valign="top"><label for="description">项目描述：</label></td>
						<td valign="top" colspan="2"><textarea name="description" id="description" cols="60" rows="10"><c:out value="${project.description }" /></textarea> 
								<font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
					</tr>
				</table>
			</form>
			<table id="attview" class="tablesorter" style="width: 90%; float: right;">
			          <thead>
			              <tr><td colspan="4"><font size="3" ><b>附件：</b></font></td></tr>
				          <tr><th>文件名</th><th>上传时间</th><th>上传者</th></tr>
			          </thead>
			          <tbody>
			              <c:forEach var="model" items="${attachList}">
			              <tr><td>${model.name}</td><td>${model.createTime}</td><td>${user.cnname}</td></tr>
			              </c:forEach>
			              <c:if test="${fn:length(attachList)<=0}">
			                <tr>
			                  <td colspan="3">暂时还未上传任何附件!</td>
			                </tr>
			              </c:if>
	                  </tbody>
	            </table>
			</div>
			<div style="float: left; width: 100%; padding-left: 8%;">
				<input type="button" id="btn_update" value="提交" style="width: 80px;" /> 
				<input type="button" id="btn_back" value="返回" onclick="back();" style="width: 80px;" />
				<input type="button" id="btn_upload" value="新增附件" onclick="updpchange();" style="width: 80px;" />
			</div>
			<div id="uploadDiv" style="float: left; width: 100%; padding-left: 8%; display: none;">
				<fieldset>
				   <legend>上传附件：</legend>
				   <input type="file" name="uploadify" id="file_upload" />   
				   <hr>   
		           <a onclick="startUpload();" href="javascript:void(0);">开始上传</a>    
		           <a href="javascript:$('#file_upload').uploadify('cancel', '*')" >取消所有上传</a>   
		        </fieldset>
		    </div>
	</div>
	<div style="float:left; width: 450px;  margin:0 0 0 5px ">  
    	<div id="commentSet">
    	<c:forEach var="comment" items="${comments}" varStatus="status">
         	<div style="word-wrap:break-word; word-break:normal; margin: 10px 0 0 0; line-height: 1.6;">
         		<fmt:formatDate value="${comment.createTime}" type="both" dateStyle="medium" timeStyle="medium" />
         		&nbsp;&nbsp;<font color="red">${comment.userCnname}</font>：
         		<span style="color:#00A;">${comment.content}</span>
         	</div>
    	</c:forEach>
    	</div>
	    	
	    <div>
	    	<form id="commentForm" method="post" action="pjcost/project/view.do">
	    		<input type="hidden" name="objectId" value="${project.id}" />
	    		<input type="hidden" name="userEnname" value="userenname" />
	    		<input type="hidden" name="objectType" value="2" />
		    	<table style="margin:20px 0 0 0;">
		    		<tr>
		            	<td valign="top"><label for="content">新回复：</label></td>
		            	<td valign="top"><textarea name="content" id="content" cols="40" rows="3"><c:out value=""/></textarea></td>
		            </tr>
		            <tr>
		            	<td></td>
		            	<td>
		            		<input type="submit" id="btn_insert" value="提交" style="width:80px;" />
		            		<input type="button" id="btn_back" onclick="back();" value="返回" style="width:80px;" />
		            	</td>
		          </tr>
		    	</table>
	    	</form>
	    </div> 
	  </div>
	  </div>
</body>
</html>